#pragma once


#include "abstractmodel.h"
#include "PolySurface.h"
#include "ColorRGBA.h"
#include "MinMaxBox.h"

#include <WinDef.h>
#include <list>
using std::list;


class PolyObject : public AbstractModel, public MinMaxBox
{
	public:

		PolyObject( )
        {
        }

		PolyObject( ColorRGBA color )
            : objectColor( color )
        {
        }

		virtual void draw( ) const
        {
			for( list<PolySurface>::const_iterator s = surfaces.begin( );
				 s != surfaces.end( );
                 ++s)
            {
				s->draw( );
			}
		}

		virtual void drawVertexNormals( ) const
        {
            glBegin( GL_LINES );
			for( list<PolySurface>::const_iterator s = surfaces.begin( );
				 s != surfaces.end( );
                 ++s )
            {
				s->drawVertexNormals( );
			}
            glEnd( );

		}

        virtual void drawFaceNormals( ) const
        {
            for( list<PolySurface>::const_iterator s = surfaces.begin( );
                 s != surfaces.end( );
                 ++s )
            {
                s->getNormal( ).draw( );
            }
        }

		virtual PolyObject& addSurface( PolySurface& surface )
        {
			surface.setSurfaceColor( objectColor );
			this->setMaxX( max( surface.getMaxX( ), this->getMaxX( ) ) );
			this->setMaxY( max( surface.getMaxY( ), this->getMaxY( ) ) );
			this->setMaxZ( max( surface.getMaxZ( ), this->getMaxZ( ) ) );

			this->setMinX( min( surface.getMinX( ), this->getMinX( ) ) );
			this->setMinY( min( surface.getMinY( ), this->getMinY( ) ) );
			this->setMinZ( min( surface.getMinZ( ), this->getMinZ( ) ) );
			surfaces.push_back( surface);
			return *this;
		}

		virtual PolyObject& setColor( ColorRGBA& color )
        {
			objectColor = color;
			return *this;
		}

		virtual const ColorRGBA& getColor( ) const
        {
			return objectColor;
		}

        virtual void enableColor( )
        {
            for( list<PolySurface>::iterator s = surfaces.begin( );
                s != surfaces.end( );
                ++s )
            {
                s->enableColor( );
            }
        }

        virtual void disableColor( )
        {
            for( list<PolySurface>::iterator s = surfaces.begin( );
                 s != surfaces.end( );
                 ++s )
            {
                s->disableColor( );
            }
        }


    private:
		std::list<PolySurface> surfaces;
		ColorRGBA objectColor;
};